let fs = require("fs");

// 引入类
let Player = require("../modules/Player");
let Game = require("../modules/Game");
let Judge = require("../modules/Judge");
let Event = require("../modules/Event");
let Score = require("../modules/Score");
let Log = require("../modules/Log");

var ObjectID = require("mongodb").ObjectID;
// 处理表单提交
var formidable = require("formidable");
// 引入自定义工具
var zty = require('../public/js/zty');
var excel2json = zty.excel2json;
var resbody = zty.resbody;


// 测试
exports.test = function(req, res, next) {
  try {
    Game.remove(
      { gameId: '011547424724265' }, err => {
      if (err) {
        res.json({
          status: 500
        });
        return
      }
      res.json({
        status: 200
      });
    })
  } catch (e) {
    console.log(e);
  }
};


// 显示导入运动员页
exports.showIndex = function(req, res, next) {
  if (req.session.login) {
    res.redirect("/" +　req.session.userType);
  } else {
    res.redirect("/signIn");
  }
};




// 显示导入运动员页
exports.showImportPlayer = function(req, res, next) {
    res.render("importPlayer", {
      pageName: "运动员：导入",
      login: req.session.login,
      userId: req.session.userId,
      userType: req.session.userType
    });
};
// 显示运动员列表页面
exports.showPlayerList = function(req, res, next) {
  res.render("playerList", {
    pageName: "运动员",
    login: req.session.login,
    userId: req.session.userId,
    userType: req.session.userType
  });
};


// 显示新建运动项目页面
exports.showNewEvent = function(req, res, next) {
  res.render("newEvent", {
    pageName: "运动项目：新建",
    login: req.session.login,
    userId: req.session.userId,
    userType: req.session.userType
  });
};
// 显示运动项目列表页面
exports.showEventList = function(req, res, next) {
  res.render("eventList", {
    pageName: "运动项目",
    login: req.session.login,
    userId: req.session.userId,
    userType: req.session.userType
  });
};



// 显示新建比赛页面
exports.showNewGame = function(req, res, next) {
    res.render("newGame", {
      pageName: "比赛：新建",
      login: req.session.login,
      userId: req.session.userId,
      userType: req.session.userType
    });
};

// 显示导入裁判页
exports.showImportJudge = function(req, res, next) {
  res.render("importJudge", {
    pageName: "裁判：导入",
    login: req.session.login,
    userId: req.session.userId,
    userType: req.session.userType
  });
};
// 显示裁判列表页面
exports.showJudgeList = function(req, res, next) {
  res.render("judgeList", {
    pageName: "裁判",
    login: req.session.login,
    userId: req.session.userId,
    userType: req.session.userType
  });
};

// 显示比赛安排页面
exports.showArrangeList = function(req, res, next) {
  res.render("arrangeList", {
    pageName: "比赛安排",
    login: req.session.login,
    userId: req.session.userId,
    userType: req.session.userType
  });
};

// 显示导入成绩页
exports.showImportScore = function(req, res, next) {
  res.render("importScore", {
    pageName: "成绩：导入",
    login: req.session.login,
    userId: req.session.userId,
    userType: req.session.userType
  });
};
// 显示成绩列表页面
exports.showScoreList = function(req, res, next) {
  res.render("scoreList", {
    pageName: "成绩",
    login: req.session.login,
    userId: req.session.userId,
    userType: req.session.userType
  });
};


// 显示比赛结果统计页面
exports.showStatistic = function(req, res, next) {
  res.render("statistic", {
    pageName: "结果统计",
    login: req.session.login,
    userId: req.session.userId,
    userType: req.session.userType
  });
};

// 显示登录页
exports.showSignIn = function(req, res, next) {
  res.render("signIn", {
    pageName: "登录"
  });
};



// 显示管理员页
exports.showAdmin = function(req, res, next) {
  res.render("admin", {
    pageName: "管理员",
    login: req.session.login,
    userId: req.session.userId,
    userType: req.session.userType
  });
};

// 显示运动员页
exports.showPlayer = function(req, res, next) {
  res.render("player", {
    pageName: "运动员",
    login: req.session.login,
    userId: req.session.userId,
    userType: req.session.userType
  });
};










